import * as SSKEYS from '@/common/session-storage-keys.js'


// 存储节点变量名
let storageNodeKeys = [SSKEYS.ACCOUNT_AVATAR_KEY, SSKEYS.ACCOUNT_NAME_KEY, SSKEYS.ACCOUNT_ROLES_KEY, SSKEYS
	.ACCOUNT_PERMISSIONS_KEY
]

// 存储的数据
let storageData = uni.getStorageSync(SSKEYS.ACCOUNT_STORAGE_DATA_KEY) || {}

const storage = {
	set: function(key, value) {
		if (storageNodeKeys.indexOf(key) != -1) {
			let tmp = uni.getStorageSync(SSKEYS.ACCOUNT_STORAGE_DATA_KEY)
			tmp = tmp ? tmp : {}
			tmp[key] = value
			uni.setStorageSync(SSKEYS.ACCOUNT_STORAGE_DATA_KEY, tmp)
		}
	},
	get: function(key) {
		// console.log(key)
		// console.log(storageData[key])
		return storageData[key] || ""
	},
	remove: function(key) {
		delete storageData[key]
		uni.setStorageSync(SSKEYS.ACCOUNT_STORAGE_DATA_KEY, storageData)
	},
	clean: function() {
		uni.removeStorageSync(SSKEYS.ACCOUNT_STORAGE_DATA_KEY)
	}
}

export default storage
